#!/bin/bash
workdir=/infra/STEP/scripts_step/puppet
tmpdir=/tmp
function cleanup {
echo limpando temporarios
rm -rf $workdir/ntlmaps-0.9.9.0.1/server.cfg
echo limpando variaveis
unset PASS
unset USER
echo processos
pkill -9 -f 'python main.py'
exit
}
trap 'cleanup;' SIGINT SIGQUIT SIGTERM 
read -p "usuario: " USER
read -s -p "senha: " PASS
sed "s/USER:/USER:${USER}/g;s/PASSWORD:/PASSWORD:${PASS}/g" $workdir/ntlmaps-0.9.9.0.1/server.cfg.orig > $workdir/ntlmaps-0.9.9.0.1/server.cfg
wait
unset PASS
unset USER
cd $workdir/ntlmaps-0.9.9.0.1
python main.py &
#echo "Aguardando proxy"
#{ tail -f $workdir/out.log & } | grep -q -m 1 -E "Now listening at .* on port 5865"
export http_proxy=http://localhost:5865
sem=/bin/true
while $sem 
do
sleep 1
if netstat -ltpn | grep 5865
then
sem=/bin/false
fi
done
cd $tmpdir
echo baixando
wget -c http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm
rpm -ivh $tmpdir/puppetlabs-release-6-6.noarch.rpm
yum --disablerepo=* --enablerepo=puppet*  install puppet
ntml_pid=$!
wait
